#include "hzpch.h"
#include "OpenGLContext.h"

#include <GLFW/glfw3.h>
#include <glad/glad.h>
namespace Hazel
{
	OpenGLContext::OpenGLContext(GLFWwindow* windowHandle)
		: m_windowHandle(windowHandle)
	{
		HZ_CORE_ASSERT(windowHandle, "Window handle is null!");

	}
	void OpenGLContext::Init()
	{
		HZ_PROFILE_FUNCTION();

		glfwMakeContextCurrent(m_windowHandle);
		int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
		HZ_CORE_ASSERT(status, "Failed to initialize Glad!");
		glGetString(GL_VENDOR);
		HZ_CORE_INFO("OpenGL Vendor: {0}", (const char*)glGetString(GL_VENDOR));
		HZ_CORE_INFO("OpenGL Renderer: {0}", (const char*)glGetString(GL_RENDERER));
		HZ_CORE_INFO("OpenGL Version: {0}", (const char*)glGetString(GL_VERSION));
		
#ifdef HZ_ENABLE_ASSERTS
		int versionMagor;
		int versionMinor;
		glGetIntegerv(GL_MAJOR_VERSION, &versionMagor);
		glGetIntegerv(GL_MINOR_VERSION, &versionMinor);

		HZ_CORE_ASSERT(versionMagor > 4 || (versionMagor == 4 && versionMinor >= 5), "Hazel requires at least OpenGL version 4.5!");
#endif // HZ_ENABLE_ASSERTS

	}
	void OpenGLContext::SwapBuffers()
	{
		HZ_PROFILE_FUNCTION();

		glfwSwapBuffers(m_windowHandle);
	}
}